﻿#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <thread>

#include "Pool.h"


static std::mutex outmtx;

int main()
{

	Pool<std::string, 10> pool{ "123456" };
  
	for (auto i = 0; i < 12; ++i) {
		std::thread([&pool, i]() {
			auto s1 = pool.acquire();
			if (s1)
			{
				*s1 = std::to_string(i);
				outmtx.lock();
				std::cout << *s1 << '\t' << pool.remaining() << '\n';
				outmtx.unlock();
			}
			pool.restore(s1);

			}).detach();
	}

	// 上面使用的detach方法，退出main函数前需要等待所有线程自然退出
	getchar();
	std::cout << pool.remaining() << '\n';
	return 0;

}
